import { defineStore } from 'pinia'

export const useChatStore = defineStore('chat', {
  state: () => ({
    messages: [],
    loading: false,
    lastMessageTime: null
  }),
  
  actions: {
    addMessage(message) {
      if (!this.messages) {
        this.messages = []
      }
      this.messages.push({
        ...message,
        timestamp: message.timestamp || new Date().toISOString()
      })
      this.lastMessageTime = new Date().toISOString()
    },
    
    setLoading(status) {
      this.loading = status
    },
    
    clearMessages() {
      this.messages = []
      this.lastMessageTime = null
    }
  },
  
  getters: {
    hasMessages: (state) => state.messages && state.messages.length > 0,
    lastMessage: (state) => state.messages && state.messages.length > 0 ? state.messages[state.messages.length - 1] : null
  }
}) 